package com.jackrain.nea.ad.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.jackrain.nea.ad.api.CmenuTreeCmd;
import com.jackrain.nea.ext.permission.Permissions;
import com.jackrain.nea.ext.permission.MenuNode;
import com.jackrain.nea.config.Resources;
import com.jackrain.nea.exception.NDSException;
import com.jackrain.nea.sys.CommandAdapter;
import com.jackrain.nea.util.ValueHolder;
import com.jackrain.nea.web.query.QuerySession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Collection;

/**
 * @author lzm
 * @date 2017-11-15
 */
@Slf4j
@Component
@Service(protocol = "dubbo", validation = "true", version = "1.0", group = "ad")
public class CmenuTreeCmdImpl extends CommandAdapter implements CmenuTreeCmd {
    @Override
    public ValueHolder execute(QuerySession session) throws NDSException {
        Collection<MenuNode> data = Permissions.getAllMenus(true);
        ValueHolder result = new ValueHolder();
        result.put("code", 0);
        result.put("message", Resources.getMessage("Success", session.getLocale()));
        try {
            result.put("data", data);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return result;
    }
}
